package com.xxljob.job;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.util.ShardingUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

/**
 * @Author: TongRui乀
 * @Date: 2019-12-13 16:05
 * @description：
 */
@Slf4j
@Component
public class XxlJobExample {

    /**
     * @param param
     * @return
     */
    @XxlJob("mySimpleJob")
    public ReturnT<String> mySimpleJob(String param) {

        log.info("mySimpleJob 执行 参数：{} 当前时间{}", param, DateTimeFormatter.ofPattern("HH:mm:ss").format(LocalTime.now()));

        return ReturnT.SUCCESS;
    }


    @XxlJob("shardingJob")
    public ReturnT<String> shardingJob(String param){

        ShardingUtil.ShardingVO shardingVo = ShardingUtil.getShardingVo();

        log.info("shardingJob 执行 当前时间:{}, 当前sharding:{} 参数：{}",  DateTimeFormatter.ofPattern("HH:mm:ss").format(LocalTime.now()), shardingVo.getIndex(), param);

        return ReturnT.SUCCESS;
    }

}
